function model=update_phi_1(model, data, n)

%global model;

k     = model.k;
k_hat = model.k_hat;


temp=zeros(1,k);
for l=1:model.r1
 
 tempw     = data.dataw1(l).w(n,:);
 tempwind  = find(tempw==1);
 if(isempty(tempwind)==1)
     keyboard;
 end
 for i=1:k
     
  temp(i) = model.alpha_1(n,i) + log(model.beta_1(l,i).beta(tempwind));
  
 end
 
 logsum=0;
 for i=1:k   
  logsum=sumlog(temp(i),logsum);
 end

 for i=1:k 
  if(logsum-temp(i)>50)
     model.phi_1(n,l,i)=model.MINVALUE;  
     disp('underflow');
  else   
     model.phi_1(n,l,i)=exp(temp(i)-logsum)+model.MINVALUE;
  end
 end

 model.phi_1(n,l,:)=model.phi_1(n,l,:)/sum(model.phi_1(n,l,:));

end



end
